package com.bankcomm.creditcard.redfriday;

import android.app.Application;

import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.MKEvent;
import com.baidu.mapapi.MKGeneralListener;

public class MyApplication extends Application {

	private static final String TAG = "MyApplication";

	// 百度MapAPI的管理类
	private BMapManager mBMapMan = null;

	/**
	 * @return the mBMapMan
	 */
	public BMapManager getBMapManager() {
		return mBMapMan;
	}

	// 授权Key
	// TODO: 请输入您的Key,
	// 申请地址：http://dev.baidu.com/wiki/static/imap/key/
	private final static String MAP_KEY = "CB4A319190801534C77322D117B938F381B4BE67";
	private boolean m_bKeyRight = true; // 授权Key正确，验证通过

	// 常用事件监听，用来处理通常的网络错误，授权验证错误等
	class MyGeneralListener implements MKGeneralListener {
		@Override
		public void onGetNetworkState(int iError) {
			// Toast.makeText(getApplicationContext(), "您的网络出错啦！",
			// Toast.LENGTH_LONG).show();
		}

		@Override
		public void onGetPermissionState(int iError) {
			if (iError == MKEvent.ERROR_PERMISSION_DENIED) {
				// 授权Key错误：
				// Toast.makeText(getApplicationContext(),
				// "请在BMapApiDemoApp.java文件输入正确的授权Key！", Toast.LENGTH_LONG)
				// .show();
				m_bKeyRight = false;
			}
		}

	}

	@Override
	public void onCreate() {
		mBMapMan = new BMapManager(this);
		mBMapMan.init(MAP_KEY, new MyGeneralListener());
		mBMapMan.start();
		super.onCreate();
	}

	@Override
	// 建议在您app的退出之前调用mapadpi的destroy()函数，避免重复初始化带来的时间消耗
	public void onTerminate() {
		// TODO Auto-generated method stub
		if (mBMapMan != null) {
			mBMapMan.stop();
			mBMapMan.destroy();
			mBMapMan = null;
		}
		super.onTerminate();
	}

}
